var findShortestSubArray = (nums) => {
  let numMap = {}
  let max = 0
  let minLength = 0
  nums.forEach((e, i) => {
    if (!numMap[e]) {
      numMap[e] = [i]
    } else {
      numMap[e].push(i)
    }

    if (numMap[e].length > max) {
      minLength = numMap[e][max] - numMap[e][0]
      max++
    } else if (numMap[e].length == max) {
      minLength = Math.min(minLength, numMap[e][max - 1] - numMap[e][0])
    }
  })
  return minLength + 1
}

console.log(findShortestSubArray([1, 2, 2, 3, 1]))
console.log(findShortestSubArray([1]))